﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:odc="clr-namespace:Odyssey.Controls"
        xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Odyssey;Component/Themes/Ribbon/InternalRibbonButton.xaml" />
        <ResourceDictionary Source="pack://application:,,,/Odyssey;Component/Themes/Ribbon/DefaultRibbonButtonBrushes.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <VerticalAlignment x:Key="{ComponentResourceKey odc:Skins, ApplicationMenuButtonVAlign}">Center</VerticalAlignment>
    <HorizontalAlignment x:Key="{ComponentResourceKey odc:Skins, ApplicationMenuButtonHAlign}">Center</HorizontalAlignment>

    <ControlTemplate TargetType="{x:Type odc:RibbonBar}" x:Key="RibbonBarTemplate">
        <Border Background="{TemplateBinding Background}" x:Name="border" Focusable="False" BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}">
            <Grid x:Name="grid" Margin="{TemplateBinding Padding}" Focusable="False" SnapsToDevicePixels="True">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition x:Name="tabColumn" Width="3*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="104" x:Name="windowButtonsPlaceHolder" />
                </Grid.ColumnDefinitions>
                <Canvas Grid.ColumnSpan="2" VerticalAlignment="Top" x:Name="PART_TitlePlaceholder" IsHitTestVisible="False">
                    <TextBlock x:Name="PART_WindowTitle"
                            Text="{Binding Path=Title, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"
                            VerticalAlignment="Center" HorizontalAlignment="Stretch" TextBlock.TextAlignment="Center" Margin="0,3,0,0"
                            TextBlock.Foreground="{Binding Path=WindowTitleBrush, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=odc:RibbonWindow}}"
                            TextTrimming="CharacterEllipsis" TextBlock.FontWeight="Bold" />
                </Canvas>
                <Border x:Name="PART_ButtonsPlaceholder" Grid.Column="2" />

                <Grid HorizontalAlignment="Left" x:Name="titleGrid" Panel.ZIndex="2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="1.5*" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="24" />
                        <RowDefinition Height="24" />
                    </Grid.RowDefinitions>

                    <!--Note: using a ContentControl instead of a ContentPresenter enables binding:-->
                    <ContentControl x:Name="AppMenuPlaceHolder" Grid.RowSpan="2" Grid.Column="0" Content="{TemplateBinding ApplicationMenu}" Focusable="False"
                            HorizontalAlignment="{DynamicResource {ComponentResourceKey odc:Skins, ApplicationMenuButtonHAlign}}"
                            VerticalAlignment="{DynamicResource {ComponentResourceKey odc:Skins, ApplicationMenuButtonVAlign}}" />

                    <ContentControl x:Name="PART_TopQaPresenter" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,-2,0,0"
                            Focusable="False" />

                    <!--The purpose of this control is just a placeholder so that the BreadcrumbBar can get the position from this control to calculate the position of the windows title:-->
                    <Border x:Name="PART_LeftWindowTitlePlaceHolder" Grid.Column="2" Visibility="Hidden" />

                    <!--Note: using a ContentControl instead of a ContentPresenter enables binding:-->
                    <ContentControl x:Name="ContextualTabPlaceHolder" Grid.Column="3" Grid.RowSpan="2" Content="{TemplateBinding ContextualTabSet}"
                            Margin="0,1,0,0" Focusable="False" VerticalAlignment="Top" HorizontalAlignment="Right" />

                    <!--The purpose of this control is just a placeholder so that the BreadcrumbBar can get the position from this control to calculate the position of the windows title:-->
                    <Border Width="0" x:Name="PART_RightWindowTitlePlaceHolder" Grid.Column="4" Visibility="Hidden" />

                    <odc:RibbonTabItemPanel x:Name="PART_TabItemContainer" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="4" Grid.IsSharedSizeScope="True"
                            IsHitTestVisible="True" Margin="3,0,0,-1" Focusable="False"
                            SeparatorBrush="{DynamicResource {ComponentResourceKey odc:Skins, RibbonTabSeparatorBrush}}" Height="24" Panel.ZIndex="2"
                            TextBlock.Foreground="{DynamicResource {ComponentResourceKey odc:Skins, RibbonForegroundBrush}}" HorizontalAlignment="Right"
                            VerticalAlignment="Bottom" />

                </Grid>

                <odc:RibbonTabScroller x:Name="TabScroller" Grid.Row="1" Grid.ColumnSpan="3" Padding="4,1,4,1" Focusable="False"
                        Color="{Binding Color, RelativeSource={RelativeSource TemplatedParent}}"
                        Alignment="{Binding GroupAlignment, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}">
                    <ItemsControl Height="100" x:Name="PART_GroupPanel" Focusable="False">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal" Focusable="False" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </odc:RibbonTabScroller>

                <StackPanel x:Name="bottomBorder" Grid.Row="2" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" Visibility="Collapsed" Focusable="False">
                    <Border Height="1" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource {ComponentResourceKey odc:Skins, BorderBrush}}" />
                    <Border Height="1" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource {ComponentResourceKey odc:Skins, LightBorderBrush}}" />

                    <Popup IsOpen="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent},  Mode=OneWay}" PopupAnimation="Fade" Focusable="False"
                            StaysOpen="True" VerticalOffset="-2" Placement="Bottom" x:Name="PART_Popup" AllowsTransparency="True" SnapsToDevicePixels="True">
                        <mwt:SystemDropShadowChrome Margin="0,0,5,5" Color="#41000000" Name="Shdw" Width="{TemplateBinding FrameworkElement.ActualWidth}"
                                CornerRadius="4">
                            <Border Width="{Binding ActualWidth, ElementName=bottomBorder}" Background="Transparent" Focusable="False"
                                    SnapsToDevicePixels="True">
                                <odc:RibbonTabScroller Padding="4,1,4,1" Grid.Row="1" Panel.ZIndex="-1"
                                        Color="{Binding Color, RelativeSource={RelativeSource TemplatedParent}}" CanAnimate="False"
                                        Alignment="{Binding GroupAlignment, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}">
                                    <ItemsControl Height="100" x:Name="PART_PopupGroupPanel">
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <StackPanel Orientation="Horizontal" />
                                            </ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                    </ItemsControl>
                                </odc:RibbonTabScroller>
                            </Border>
                        </mwt:SystemDropShadowChrome>
                    </Popup>
                </StackPanel>

                <!--Note: using a ContentControl instead of a ContentPresenter enables binding:-->
                <ContentControl Grid.Row="3" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" x:Name="bottmQaPresenter" Visibility="Collapsed"
                        Focusable="False" />

            </Grid>
        </Border>

        <ControlTemplate.Triggers>
            <Trigger Property="IsContextualTabVisible" Value="False">
                <Setter Property="Grid.ColumnSpan" Value="3" TargetName="PART_LeftWindowTitlePlaceHolder" />
                <Setter Property="Grid.ColumnSpan" Value="5" TargetName="PART_TabItemContainer" />
                <Setter Property="Grid.ColumnSpan" Value="2" TargetName="titleGrid" />
                <Setter Property="Width" Value="*" TargetName="tabColumn" />
            </Trigger>

            <Trigger Property="CanMinimize" Value="False">
                <Setter Property="ItemsSource" Value="{Binding SelectedGroups, RelativeSource={RelativeSource TemplatedParent}}" TargetName="PART_GroupPanel" />
            </Trigger>

            <Trigger Property="CanMinimize" Value="True">
                <Setter Property="Visibility" Value="Visible" TargetName="bottomBorder" />
                <Setter Property="Visibility" Value="Collapsed" TargetName="TabScroller" />
                <Setter Property="ItemsSource" Value="{Binding SelectedGroups, RelativeSource={RelativeSource TemplatedParent}}"
                        TargetName="PART_PopupGroupPanel" />
            </Trigger>

            <Trigger Property="ToolbarPlacement" Value="Bottom">
                <Setter TargetName="PART_TopQaPresenter" Property="Visibility" Value="Collapsed" />
                <Setter TargetName="bottmQaPresenter" Property="Visibility" Value="Visible" />
                <Setter TargetName="bottmQaPresenter" Property="Content" Value="{Binding QAToolBar, RelativeSource={RelativeSource TemplatedParent}}" />
            </Trigger>

            <Trigger Property="ToolbarPlacement" Value="Top">
                <Setter TargetName="PART_TopQaPresenter" Property="Content" Value="{Binding QAToolBar, RelativeSource={RelativeSource TemplatedParent}}" />
            </Trigger>

            <Trigger Property="IsRibbonVisible" Value="False">
                <Setter Property="Visibility" Value="Collapsed" TargetName="PART_TabItemContainer" />
                <Setter Property="Visibility" Value="Collapsed" TargetName="TabScroller" />
            </Trigger>

            <Trigger Property="IsMinimized" Value="True">
                <Setter Property="Visibility" Value="Collapsed" TargetName="PART_TabItemContainer" />
                <Setter Property="Visibility" Value="Collapsed" TargetName="PART_TopQaPresenter" />
                <Setter Property="Visibility" Value="Collapsed" TargetName="TabScroller" />
                <Setter Property="Visibility" Value="Collapsed" TargetName="bottmQaPresenter" />
            </Trigger>

            <DataTrigger Binding="{Binding Path=IsGlassOn, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=odc:RibbonWindow}}" Value="True">
                <Setter Property="BitmapEffect" TargetName="PART_WindowTitle">
                    <Setter.Value>
                        <OuterGlowBitmapEffect GlowColor="White" GlowSize="3" Opacity="0.75" />
                    </Setter.Value>
                </Setter>
            </DataTrigger>

            <DataTrigger Binding="{Binding Path=WindowState, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=odc:RibbonWindow}}"
                    Value="Maximized">
                <Setter Property="Effect" TargetName="PART_WindowTitle" Value="{x:Null}" />
            </DataTrigger>

        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style TargetType="{x:Type odc:RibbonBar}">
        <Setter Property="Template" Value="{StaticResource RibbonBarTemplate}" />
        <Setter Property="Foreground" Value="{DynamicResource {ComponentResourceKey odc:Skins, RibbonForegroundBrush}}" />
        <Setter Property="Margin" Value="1,0,1,0" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="FontWeight" Value="Normal" />
        <Setter Property="FontSize" Value="12" />
    </Style>

</ResourceDictionary>